package com.shareach.http.controller;

import org.codehaus.jackson.type.TypeReference;

import com.shareach.basic.HttpBase;
import com.shareach.dao.redis.impl.DeployRDao.DeployType;
import com.shareach.util.JsonUtil;
import com.shareach.web.basic.Answer;

public class DeployUtils extends HttpBase {
	private String host;
	public DeployUtils(String host){
		this.host = host;
	}
	/**
	 * 微博数据上传
	 * 
	 * @param brand
	 * @return
	 */
	public void clear(DeployType type) {
		try {
			String url = host + "/deploy/";
			switch(type){
				case Activity:
					url += "clearActivity";
					break;
				case Card:
					url += "clearCard";
					break;
				case Ticket:
					url += "clearTicket";
					break;
				case Tuan:
					url += "clearTuan";
					break;
				case Shop:
					url += "clearShop";
					break;
				default:
					throw new RuntimeException("清理类型错误。");
			}
			String resultString = this.httpPost(url+".do", null, null);
			Answer<String> result = JsonUtil.objectFromJson(resultString, new TypeReference<Answer<String>>() {
			});
			if (result.getCode() == 0) {
			} else {
				throw new RuntimeException("清理上架的 "+type.getText()+" 数据错误" + result.getMsg());
			}
		} catch (Exception exp) {
			//exp.printStackTrace();
			throw new RuntimeException(exp);
		}
	}
}
